{% extends 'base.html' %}

{% block title %}{{ pet.name }} - 宠物详情{% endblock %}

{% block content %}
<div class="row">
    <!-- 宠物图片 -->
    <div class="col-md-6">
        <div class="card mb-4">
            <img src="{{ pet.image.url }}" class="card-img-top" alt="{{ pet.name }}" style="height: 400px; object-fit: contain; background-color: #f8f9fa;">
        </div>
    </div>

    <!-- 宠物信息 -->
    <div class="col-md-6">
        <h2 class="mb-3">{{ pet.name }}</h2>
        <div class="card mb-4">
            <div class="card-body">
                <table class="table table-borderless">
                    <tr>
                        <td class="fw-bold">宠物类型</td>
                        <td>{{ pet.type.name }}</td>
                    </tr>
                    <tr>
                        <td class="fw-bold">年龄</td>
                        <td>{{ pet.age }}岁</td>
                    </tr>
                    <tr>
                        <td class="fw-bold">性别</td>
                        <td>{{ pet.get_gender_display }}</td>
                    </tr>
                    <tr>
                        <td class="fw-bold">领养状态</td>
                        <td>
                            {% if pet.status == 'available' %}
                                <span class="badge bg-success">可领养</span>
                            {% elif pet.status == 'pending' %}
                                <span class="badge bg-warning">审核中</span>
                            {% else %}
                                <span class="badge bg-secondary">已领养</span>
                            {% endif %}
                        </td>
                    </tr>
                    <tr>
                        <td class="fw-bold">发布时间</td>
                        <td>{{ pet.created_time|date:"Y-m-d H:i" }}</td>
                    </tr>
                </table>
            </div>
        </div>

        <!-- 领养按钮 -->
        {% if user.is_authenticated %}
            {% if pet.status == 'available' %}
                <a href="{% url 'apply_adoption' pet.id %}" class="btn btn-primary btn-lg">申请领养</a>
            {% elif pet.status == 'pending' %}
                <button class="btn btn-warning btn-lg" disabled>审核中，暂不可申请</button>
            {% else %}
                <button class="btn btn-secondary btn-lg" disabled>已被领养</button>
            {% endif %}
        {% else %}
            <a href="{% url 'login' %}?next={{ request.path }}" class="btn btn-primary btn-lg">登录后申请领养</a>
            <p class="mt-2">登录后即可提交领养申请，查看申请进度</p>
        {% endif %}
    </div>
</div>

<!-- 宠物描述 -->
<div class="card mt-4">
    <div class="card-header bg-light">
        <h5 class="mb-0">宠物介绍</h5>
    </div>
    <div class="card-body">
        <p class="card-text">{{ pet.description|linebreaks }}</p>
    </div>
</div>
{% endblock %}